home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / perl / os2perl / split.t < prev    next >
Text File  |  1991-06-16  |  2KB  |  58 lines

  1. #!./perl
  2.  
  3. # $Header: split.t,v 4.0 91/03/20 01:54:42 lwall Locked $
  4.  
  5. print "1..12\n";
  6.  
  7. $FS = ':';
  8.  
  9. $_ = 'a:b:c';
  10.  
  11. ($a,$b,$c) = split($FS,$_);
  12.  
  13. if (join(';',$a,$b,$c) eq 'a;b;c') {print "ok 1\n";} else {print "not ok 1\n";}
  14.  
  15. @ary = split(/:b:/);
  16. if (join("$_",@ary) eq 'aa:b:cc') {print "ok 2\n";} else {print "not ok 2\n";}
  17.  
  18. $_ = "abc\n";
  19. @xyz = (@ary = split(//));
  20. if (join(".",@ary) eq "a.b.c.\n") {print "ok 3\n";} else {print "not ok 3\n";}
  21.  
  22. $_ = "a:b:c::::";
  23. @ary = split(/:/);
  24. if (join(".",@ary) eq "a.b.c") {print "ok 4\n";} else {print "not ok 4\n";}
  25.  
  26. $_ = join(':',split(' ',"    a b\tc \t d "));
  27. if ($_ eq 'a:b:c:d') {print "ok 5\n";} else {print "not ok 5 #$_#\n";}
  28.  
  29. $_ = join(':',split(/ */,"foo  bar bie\tdoll"));
  30. if ($_ eq "f:o:o:b:a:r:b:i:e:\t:d:o:l:l")
  31.     {print "ok 6\n";} else {print "not ok 6\n";}
  32.  
  33. $_ = join(':', 'foo', split(/ /,'a b  c'), 'bar');
  34. if ($_ eq "foo:a:b::c:bar") {print "ok 7\n";} else {print "not ok 7 $_\n";}
  35.  
  36. # Can we say how many fields to split to?
  37. $_ = join(':', split(' ','1 2 3 4 5 6', 3));
  38. print $_ eq '1:2:3 4 5 6' ? "ok 8\n" : "not ok 8 $_\n";
  39.  
  40. # Can we do it as a variable?
  41. $x = 4;
  42. $_ = join(':', split(' ','1 2 3 4 5 6', $x));
  43. print $_ eq '1:2:3:4 5 6' ? "ok 9\n" : "not ok 9 $_\n";
  44.  
  45. # Does the 999 suppress null field chopping?
  46. $_ = join(':', split(/:/,'1:2:3:4:5:6:::', 999));
  47. print $_ eq '1:2:3:4:5:6:::' ? "ok 10\n" : "not ok 10 $_\n";
  48.  
  49. # Does assignment to a list imply split to one more field than that?
  50. $foo = `perl -D1024 -e "(\$a,\$b) = split;" 2>&1`;
  51. print $foo =~ /DEBUGGING/ || $foo =~ /num\(3\)/ ? "ok 11\n" : "not ok 11\n";
  52.  
  53. # Can we say how many fields to split to when assigning to a list?
  54. ($a,$b) = split(' ','1 2 3 4 5 6', 2);
  55. $_ = join(':',$a,$b);
  56. print $_ eq '1:2 3 4 5 6' ? "ok 12\n" : "not ok 12 $_\n";
  57.  
  58.